<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>龙头股</title>		
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<style type="text/css">
        .res
        {
            color: Red;
        }
		.result{
			background: Yellow;
		}
    </style>
	</head>
	<body>
	<div style="position: fixed; right: 20px; top: 0;">
        <input id="key" type="text" style="width: 120px;"/>
        <input type="button" value="下一个" onclick="next()" />
        <input type="button" value="上一个" onclick="previous()" />
    </div>
		<div id="towrite"></div>		
		<div id="towrite2" class="fixedBox"></div>		
		<script>
			window.onload = function() {
			getSource2();
			changeStyle();			
			getSource1();	
			setTimeout("getSource3()","3000"); 	
//getSource3();	
  
			}
			

			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource2();					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
			
			function changeStyle() {
				var obj = document.getElementById("towrite2");			  
				obj.style.top= "30px";
				obj.style.left="600px";				  		  
				obj.style.width= "330px";
				obj.style.height= "400px";				
			}
			
			var c = 1;
			function closeStyle() {				
				var obja = document.getElementById("fb");							               
				if(obja.innerText=="▲")
				{
					obja.innerText="▼";	
					var obj1 = document.getElementById("towrite2");
					obj1.style.height= "30px";
					c = 0;
				}
				else if(obja.innerText=="▼")	
				{
					obja.innerText="▲";	
					changeStyle();	
					c = 1;
				}			
			}	

			
				Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			
			function createXmlHttp1() {
				if (window.XMLHttpRequest) {
				xmlHttp1 = new XMLHttpRequest();				
				} else {
				xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");				
				}
			}
			
			function createXmlHttp2() {
				if (window.XMLHttpRequest) {				
				xmlHttp2 = new XMLHttpRequest();
				} else {				
				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			
			function createXmlHttp3() {
				if (window.XMLHttpRequest) {				
				xmlHttp3 = new XMLHttpRequest();
				} else {				
				xmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
						
			
			function getSource1() {	    				
				var url1 = "龙头股1.json"; 
				createXmlHttp1();
				xmlHttp1.onreadystatechange = writeSource1;
				xmlHttp1.open("GET", url1, true);
				xmlHttp1.send(null);
			}
				
			function getSource3() {	    				
				var url3 = "龙头股2.json"; 
				createXmlHttp3();
				xmlHttp3.onreadystatechange = writeSource3
				xmlHttp3.open("GET", url3, true);
				xmlHttp3.send(null);
			}
				
			function getSource2() {	
				var url2 = "http://zx.10jqka.com.cn/hotblock/proxy/block/platerankinfo?callback=jQuery183035776317082556974_1624191358973&platetype=concept"; 
				createXmlHttp2();
				xmlHttp2.onreadystatechange = writeSource2;
				xmlHttp2.open("GET", url2, true);
				xmlHttp2.send(null);
			}
				
			function update(ss) {
				//alert(ss);
				var dms=ss.split('#');
				dm = dms[0];
				bk = dms[1];				
				$('#key').val(dm);	
				next();														
			}
			
			function writeSource1() { 
				if (xmlHttp1.readyState == 4) {         
					var data = xmlHttp1.responseText
					//alert(data);
					//document.write(data);					
					var transform_aa = [           
					{"tag":"ul", children:function(){return(json2html.transform(this.datas, transform_bb));}}
					];
					
					var transform_bb= 
					{"tag":"p", children:[
					//{"tag": "h3", "html":"<a href='javascript:void(0);' onclick='update(\"${概念代码}\"+\"#\"+\"${概念名称}\"+\"#\"+\"0\");'>${概念代码}&nbsp;&nbsp;${概念名称}</a>"}, 											
					{"tag": "h3", "html":"${概念代码}&nbsp;&nbsp;${概念名称}"}, 
					{"tag":"ul", children:[
					{"tag": "p", "html":"${概念解析}"},    				
					{"tag":"ul", children:function(){return(json2html.transform(this.龙头股, transform_cc));}}    				
					]}]};
					
					var transform_cc= 
					{"tag":"li", children:[
					{"tag": "b", "html":"<a href='http://www.treeid/code_${股票代码}' >${股票代码}&nbsp;&nbsp;${股票名称} </a>"},
					{"tag": "p", "html":"${股票详情}"},  
					]};   

					var html = json2html.transform(data, transform_aa);					
					div=document.getElementById('towrite');
					div.innerHTML = '<h2>同花顺板块龙头</h2>' + html;												
				}
			}
			
			function writeSource3() { 
				if (xmlHttp3.readyState == 4) {         
					var data = xmlHttp3.responseText					
					//alert(data);
					//document.write(data);
					
					var transform_aa = [           
					{"tag":"ul", children:function(){return(json2html.transform(this.datas, transform_bb));}}
					];
					
					var transform_bb= 
					{"tag":"p", children:[
					<!-- {"tag": "p", "html":"<a href='javascript:void(0);' onclick='update(\"${概念代码}\"+\"#\"+\"${概念名称}\");'>${概念代码}&nbsp;&nbsp;${概念名称}</a>"}, 											 -->
					{"tag": "h3", "html":"${概念代码}&nbsp;&nbsp;${概念名称}"}, 
					{"tag":"ul", children:[
					{"tag": "p", "html":"${概念解析}"},    				
					{"tag":"ul", children:function(){return(json2html.transform(this.龙头股, transform_cc));}}    				
					]}]};
					
					var transform_cc= 
					{"tag":"li", children:[
					{"tag": "b", "html":"<a href='http://www.treeid/code_${股票代码}' >${股票代码}&nbsp;&nbsp;${股票名称} </a>"},
					{"tag": "p", "html":"${股票详情}"},  
					]};   

					var html = json2html.transform(data, transform_aa);					
					div = document.getElementById('towrite');
					div.innerHTML += html;												
				}
			}
			
			function writeSource2() { 	
				if (xmlHttp2.readyState == 4) {				
					var data2 = xmlHttp2.responseText
					data2 = data2.replace(/ /g,"")					
					data2 = "{" + data2.match(/\(\{(\S*)\}\]\}\)/)[1] + "}]}";
					//document.write(data2);
					var transform_aa2 = [           
					{"tag":"ul", children:function(){return(json2html.transform(this.result, transform_bb2));}}
					];
					var transform_bb2= 
					{"tag":"span", children:[									
					<!-- {"tag": "p", "html":"${platecode}&nbsp;&nbsp;${platename}&nbsp;&nbsp;涨幅：${increase}%"},  -->
					{"tag": "p", "html":"<a href='javascript:void(0);' onclick='update(\"${platecode}\"+\"#\"+\"${platename}\");'>${platecode}&nbsp;&nbsp;${platename}&nbsp;&nbsp;涨幅：${increase}%</a>"},
					]};
								
					var html2 = json2html.transform(data2, transform_aa2); 				
					div2 = document.getElementById('towrite2');	
					var obja = document.getElementById("fb");
					var A =	"";				
					if(c == 1){					
						A = '<a href="javascript:closeStyle();" id="fb" style="float:right; padding-top:8px">▲</a>';
					}else{ 
						A = '<a href="javascript:closeStyle();" id="fb" style="float:right; padding-top:8px">▼</a>';
					}
					
					var myDate = new Date();				
					div2.innerHTML = A + '<h4>热点板块：&nbsp;&nbsp;&nbsp;&nbsp;' + myDate.Format("hh:mm:ss") + '</h4>' + html2;	
				}
			}
		</script>	
		
		<script>
			var oldKey = "";
			var index = -1;
			var pos = new Array();
			var oldCount = 0;

			function previous(){
			index--;
			index = index < 0 ? oldCount - 1 : index;
			search();
			}
			function next(){
			index++;
			//index = index == oldCount ? 0 : index;
			if(index==oldCount){
				index = 0 ;
			}
			search();
			}

			function search() {
				$(".result").removeClass("res");
				var key = $("#key").val(); 
				if (!key) {
					console.log("key为空则退出");
					$(".result").each(function () {
					$(this).replaceWith($(this).html());
					});
					oldKey = "";
					return; 
				}
				if (oldKey != key) {
					console.log("进入重置方法");
					//重置
					index = 0;
					$(".result").each(function () {
					$(this).replaceWith($(this).html());
					});
					pos = new Array();
					var regExp = new RegExp(key+'(?!([^<]+)?>)', 'ig');//正则表达式匹配
					//$("body").html($("body").html().replace(regExp, "<span id='result" + index + "' class='result'>" + key + "</span>")); // 高亮操作
					$("#towrite").html($("#towrite").html().replace(regExp, "<span id='result" + index + "' class='result'>" + key + "</span>")); // 高亮操作
					$("#key").val(key);
					oldKey = key;
					$(".result").each(function () {
					pos.push($(this).offset().top);
					});
					oldCount = $(".result").length;
					console.log("oldCount值：",oldCount);
				}

				$(".result:eq(" + index + ")").addClass("res");
				$("body").scrollTop(pos[index] - 100);
			}
		</script>	
	</body>

</html>